import request from '@/utils/request'

const uploadPath = process.env.HOST + '/manage/file/upload.do'
const mpUploadPath = process.env.HOST + '/manage/wechat/mp/material/news/upload.do'
export { uploadPath, mpUploadPath }

/**
 * 公共服务
 * @type {{uploadFile: (function(*): *)}}
 */
export const CommonService = {
  // 文件上传
  uploadFile: function(data) { return request({ url: uploadPath, method: 'post', data }) },
  // 上传微信图文图片
  uploadNewsContentImgMaterial: function(platformId, data) { return request({ url: mpUploadPath + '?platformId=' + platformId, method: 'post', data }) }
}

/**
 * 基础数据服务
 * @type {{listDictionary: (function(*): *), addDictionary: (function(*=): *), listDictionaryByType: (function(*=): *), editDictionary: (function(*=): *), listTypes: (function(): *), deleteDictionary: (function(*): *)}}
 */
export const DictionaryService = {
  // 根据字典类型获取字典列表
  listDictionaryByType: function(type) { return request({ method: 'get', url: '/manage/dictionary/type.do', params: { type: type }}) },
  // 获取所有的字典类型
  listTypes: function() { return request({ method: 'get', url: '/manage/dictionary/types.do' }) },
  // 数据列表
  listDictionary: function(query) { return request({ method: 'get', url: '/manage/dictionary/list.do', params: { ...query }}) },
  // 新增字典
  addDictionary: function(data) { return request({ method: 'post', url: '/manage/dictionary/add.do', data: data }) },
  // 编辑字典
  editDictionary: function(data) { return request({ method: 'post', url: '/manage/dictionary/edit.do', data: data }) },
  // 删除字典
  deleteDictionary: function(id) { return request({ method: 'post', url: '/manage/dictionary/delete.do', data: [id] }) }
}

export const CityService = {
  // 所有城市列表
  listCity: function(query) { return request({ method: 'get', url: '/manage/city/list.do', params: { ...query }}) },
  // 编辑城市
  editCity: function(data) { return request({ method: 'post', url: '/manage/city/edit.do', data: data }) },
  // 新增城市
  addCity: function(data) { return request({ method: 'post', url: '/manage/city/add.do', data: data }) },
  // 删除城市
  deleteCity: function(id) { return request({ method: 'post', url: '/manage/city/delete.do', data: [id] }) },
  // 刷新缓存
  refreshCache: function() { return request({ method: 'get', url: '/manage/city/refresh/cache.do' }) },
  // 下载城市
  downloadCity: function() { return request({ method: 'get', url: '/manage/city/download.do' }) }
}
